#ifndef __CALCULATE_RESULT_EVENT_HPP__
#define __CALCULATE_RESULT_EVENT_HPP__

#include "base_event.hpp"

namespace run_code_event_space {

struct calculate_result_event : base_event<calculate_result_event>  {
    template <class U>
    ProcessStatus execute_impl(run_code_context_t<U>& context);
};

template <class U>
ProcessStatus calculate_result_event::execute_impl(run_code_context_t<U>& context) {
    context.result.testExample ++;
    context.result.passExample += context.get_latest_status().result == RUN_OK;
    if (context.runtime_info.result == WAIT_JUDGE) {
        context.runtime_info.result = context.get_latest_status().result;
    }
    if (context.get_latest_status().result != RUN_OK) {
        context.all_case_status[context.judge_type.example_index].result = context.get_latest_status().result;

        // just mark first non-RUN_OK result
        if (context.runtime_info.result == RUN_OK) {
            context.runtime_info.result = context.get_latest_status().result;
        }
    }
    return ProcessStatus{ .result = RUN_OK };
}

}

#endif /* __CALCULATE_RESULT_EVENT_HPP__ */
